﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Entity;
using School.Entities;
using School.Common;

namespace School.Pages.Teaching
{
    public partial class SuccessStatment : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LstCampuses.DataSource = Structure.GetCampuses();
                LstCampuses.DataTextField = "Name";
                LstCampuses.DataValueField = "ID";
                LstCampuses.DataBind();

                LstCertificates.DataSource = Structure.GetCertificatesByCampus(long.Parse(LstCampuses.SelectedValue));
                LstCertificates.DataValueField = "Id";
                LstCertificates.DataTextField = "Name";
                LstCertificates.DataBind();



                LstCertificates.Items.Insert(0, new ListItem() { Value = "0", Text = "اختر الشهادة" });
                LstStages.Items.Insert(0, new ListItem() { Value = "0", Text = "اختر المرحلة" });
                LstGrades.Items.Insert(0, new ListItem() { Value = "0", Text = "اختر الصف" });
                LstStudent.Items.Insert(0, new ListItem() { Value = "0", Text = "اختر الطالب" });
            }
        }

        protected void LstCampuses_SelectedIndexChanged(object sender, EventArgs e)
        {
            LstCertificates.DataSource = Structure.GetCertificatesByCampus(long.Parse(LstCampuses.SelectedValue));
            LstCertificates.DataValueField = "Id";
            LstCertificates.DataTextField = "Name";
            LstCertificates.DataBind();

            LstCertificates.Items.Insert(0, new ListItem() { Value = "0", Text = "اختر الشهادة" });
        }

        protected void LstCertificates_SelectedIndexChanged(object sender, EventArgs e)
        {
            LstStages.DataSource = Structure.GetStagesByCertificate(long.Parse(LstCertificates.SelectedValue));
            LstStages.DataValueField = "Id";
            LstStages.DataTextField = "Name";
            LstStages.DataBind();
            LstStages.Items.Insert(0, new ListItem() { Value = "0", Text = "اختر المرحلة" });
        }

        protected void LstStages_SelectedIndexChanged(object sender, EventArgs e)
        {
            LstGrades.DataSource = Structure.GetGradesByStage(long.Parse(LstStages.SelectedValue));
            LstGrades.DataValueField = "Id";
            LstGrades.DataTextField = "Name";
            LstGrades.DataBind();
            LstGrades.Items.Insert(0, new ListItem() { Value = "0", Text = "اختر الصف" });
        }

        protected void LstGrades_SelectedIndexChanged(object sender, EventArgs e)
        {
            LstStudent.DataSource = Students.GetStudentsByGrade(long.Parse(LstGrades.SelectedValue)).Select(x => new { x.Id, Name = x.Ar_FirstName + " " + x.Ar_SecondName + " " + x.Ar_ThirdNmae + " " + x.Ar_FourthName });
            LstStudent.DataValueField = "Id";
            LstStudent.DataTextField = "Name";
            LstStudent.DataBind();
            LstStudent.Items.Insert(0, new ListItem() { Value = "0", Text = "اختر الطالب" });
        }

        protected void Button1_Click(object sender, EventArgs e)
        {

        }

        protected void LstStudent_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridView1.DataSource = Gradding.GetSubjectsTotal(long.Parse(LstStudent.SelectedValue), 1);
            GridView1.DataBind();

            if (GridView1.Rows.Count > 0)
            {
                Panel1.Visible = true;
            }
        }
    }
}